package com.ruoyi.common.goEasy;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.http.HttpUtils;
import io.goeasy.GoEasy;
import io.goeasy.publish.GoEasyError;
import io.goeasy.publish.PublishListener;

/*
* goEasy工具类
* */
public class GoEasyUtils {


    private static String appkey = "BC-b331ef49cd6e4b2b8a531a594f1bf56f";
    private static String  goeasyUrl = "https://rest-hz.goeasy.io";

    private static String publishUrl = "https://rest-hz.goeasy.io/v2/pubsub/publish";



    public  static void pushMessage(String chaanel,String content){
        GoEasy goEasy = new GoEasy(goeasyUrl, appkey);
        goEasy.publish(chaanel, content,new PublishListener(){
            @Override
            public void onSuccess() {
                System.out.println("Publish success.");
            }
            @Override
            public void onFailed(GoEasyError error) {
                System.out.println("Failed to Publish message, error:" + error.getCode() + " , " + error.getContent());
            }
        });
    }


    /*
    * 通知栏  通过发送post请求
    * */
    public static void sendPublish(String channel,String content,String notification_title) {
        try {
            JSONObject jsonParam = new JSONObject();
            jsonParam.put("appkey", appkey);
            jsonParam.put("channel", channel);
            jsonParam.put("notification_title", notification_title);
            HttpUtils.sendPublish(publishUrl, jsonParam.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
